﻿using T0yK4T.IO;
using System.Collections.Generic;

namespace ToyChat.Server
{
    /// <summary>
    /// Common interface for the user handler
    /// </summary>
    public interface IUserHandler : IEnumerable<IUser>
    {
        /// <summary>
        /// Kicks the specified user
        /// </summary>
        /// <param name="user">The user to kick</param>
        void KickUser(IUser user);

        /// <summary>
        /// Attempts to add a user connecting on the specified connection
        /// <para/>
        /// If the user is authenticated - OR - registered using a loaded <see cref="ILoginModule"/>
        /// <para/>
        /// the <paramref name="user"/> parameter will be set to the resulting <see cref="IUser"/> object
        /// </summary>
        /// <param name="connection">The connection that should be used</param>
        /// <param name="user">This paramter will be set to a <see cref="IUser"/> object retrieved from a <see cref="ILoginModule"/> upon user logon / registration</param>
        /// <returns>True if the user was succesfully authenticated or registered</returns>
        bool AddUser(CryptoConnection connection, out IUser user);

        /// <summary>
        /// Removes the specified user from the internal user list (no further action is taken)
        /// </summary>
        /// <param name="user"></param>
        void RemoveUser(IUser user);

        /// <summary>
        /// Attempts to get the user with the specified UserID
        /// </summary>
        /// <param name="userID">The ID of the user to look for</param>
        /// <param name="user">Will be set to an instance of <see cref="IUser"/> if a user with the given ID was found</param>
        /// <returns>True if succesful, otherwise false</returns>
        bool TryGetUser(int userID, out IUser user);

        /// <summary>
        /// Attempts to get the user with the specified username
        /// </summary>
        /// <param name="username">The username of the user to look for</param>
        /// <param name="user">Will be set to an instance of <see cref="IUser"/> if a user with the given username was found</param>
        /// <returns>True if succesful, otherwise false</returns>
        bool TryGetUser(string username, out IUser user);
    }
}